package com.nervenets.shopping.hibernate.dao;

import com.nervenets.general.hibernate.dao.BaseDao;
import com.nervenets.shopping.hibernate.domain.order.GroupBuyOrder;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.math.BigDecimal;

public interface GroupBuyOrderDao extends BaseDao<GroupBuyOrder> {
    @Query("select new java.math.BigDecimal(COALESCE(SUM(contribution), 0)) from GroupBuyOrder where deleted = 0 and successTime > 0 ")
    BigDecimal sumOfContribution();

    @Query("select new java.math.BigDecimal(COALESCE(SUM(contribution), 0)) from GroupBuyOrder where deleted = 0 and successTime between :startTime and :endTime ")
    BigDecimal sumOfContribution(@Param("startTime") long startTime, @Param("endTime") long endTime);

    @Query("select " +
            "new java.math.BigDecimal(coalesce(sum(bonus),0)) " +
            "from GroupBuyOrder " +
            "where deleted = 0 " +
            "and createTime between :startTime and :endTime " +
            "and successTime > 0")
    BigDecimal sumOfBonusByTime(@Param("startTime") long startTime, @Param("endTime") long endTime);

    @Query("select new java.math.BigDecimal(COALESCE(SUM(bonus), 0)) from GroupBuyOrder where deleted = 0 and successTime > 0 ")
    BigDecimal sumOfBonus();

    @Query("select new java.math.BigDecimal(COALESCE(SUM(bonus), 0)) from GroupBuyOrder where deleted = 0 and successTime between :startTime and :endTime ")
    BigDecimal sumOfBonus(@Param("startTime") long startTime, @Param("endTime") long endTime);
}
